package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevCodeIccEntity;
import com.sugon.service.DevCodeIccService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.sugon.utils.ShiroUtils.getUserId;

/**
 * 设备ICC代码维护Controller
 *
 * @author sugon
 * @date 2019-07-15 11:28:13
 */
@Controller
@RequestMapping("devcodeicc")
public class DevCodeIccController {
    @Autowired
    private DevCodeIccService devCodeIccService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("devcodeicc:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevCodeIccEntity> devCodeIccList = devCodeIccService.queryList(query);
        int total = devCodeIccService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devCodeIccList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("devcodeicc:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevCodeIccEntity devCodeIcc = devCodeIccService.queryObject(id);

        return R.ok().put("devCodeIcc", devCodeIcc);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("devcodeicc:save")
    @ResponseBody
    public R save(@RequestBody DevCodeIccEntity devCodeIcc) {
        devCodeIcc.setCreateUser(getUserId());
        devCodeIcc.setCreateDate(new Date());
        devCodeIccService.save(devCodeIcc);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("devcodeicc:update")
    @ResponseBody
    public R update(@RequestBody DevCodeIccEntity devCodeIcc) {
        devCodeIcc.setUpdateUser(getUserId());
        devCodeIcc.setUpdateDate(new Date());
        devCodeIccService.update(devCodeIcc);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("devcodeicc:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devCodeIccService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevCodeIccEntity> list = devCodeIccService.queryList(params);

        return R.ok().put("list", list);
    }

}
